package cc.linker.steplink.crm.merchanth5.controller;

import cc.linker.steplink.crm.commons.domain.WxUser;
import cc.linker.steplink.crm.merchanth5.commons.RequestFilter;
import cc.linker.steplink.crm.merchanth5.service.SurvivalPushService;
import cc.linker.steplink.crm.response.GlobalException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("/scoreactive")
public class ScoreActiveCacheController {

    @Autowired
    private RequestFilter requestFilter;
    @Autowired
    private SurvivalPushService survivalPushService;


    /**
     *
     * @param pid
     * @param actType  open:分享传播 , register:邀请注册 , subscribe:分享关注公众号
     * @param request
     */
    @GetMapping("/shareAct")
    public void shareAct(String pid, String actType, HttpServletRequest request) {
        if (!StringUtils.isEmpty(pid) && !StringUtils.isEmpty(actType)) {
            WxUser wxUser =  requestFilter.getWxUser(request);
            String orgId = wxUser.getOrgId();
            String customerId = wxUser.getCustomerId();
            survivalPushService.saveShareCache(pid,actType,orgId,customerId);
        }else{
            LOGGER.error("分享传播送积分成长值参数错误->pid:"+pid+",actType:"+actType);
        }

    }

}
